{template 'header'}
{if $op == 'display'}
<script src="../addons/bsht_tbk/res/js/MagicZoom.js"></script>
<div class='container' style='padding: 0 5px 10px; margin: 0; width: 100%'>
	<ul class="nav nav-tabs">
		<li class="active"><a href="{php echo $this->createWebUrl('listcateall');}">分类列表</a></li>

		<li><a href="{php echo $this->createWebUrl('listcateall',array('op'=>'post'));}">添加/编辑分类</a></li>
	</ul>

<div class="panel panel-info">
	<div class="panel-heading"><a class="btn btn-sm btn-danger" href="{php echo $this->createWebUrl('autocateall')}"><i class="fa fa-mail-forward"></i> 初始化分类</a>
</div>
</div>

<div class="panel panel-info">
	
 
    </div>
<form action="./index.php" method="get" class="form-horizontal" role="form">
			<input type="hidden" name="c" value="site" />
			<input type="hidden" name="a" value="entry" />
        	<input type="hidden" name="m" value="bsht_tbk" />
        	<input type="hidden" name="do" value="listcateall" />
    <div style="padding:15px;">
        <table class="table table-hover">
            <thead class="navbar-inner">
                <tr style="width:100%">
				    <th style="width:3em;">
                        <input type="checkbox" id="checkall"/>
                    </th>
					<th style="width:90px;">序号</th>
				    <th width="80" style="text-align:center">ID</th>
					<th width="100" style="text-align:center">图标</th>
					<th width="auto" style="text-align:left">名称</th>
					<th style="width:90px;text-align:center">首页显示</th>
					<th style="width:auto;text-align:center">大淘客绑定</th>
					<th style="width:auto;text-align:center">好单库绑定</th>
					<th style="width:90px;text-align:center">状态</th>
					<th style="width:90px;text-align:center">顶部通告</th>
					<th width="20%" style="text-align:right">操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $row}


                <tr>
				   <td><input type="checkbox" name="ids[]" value="{$row['id']}"/></td>
                   <td><input type="text" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"  style="width:50px;font-size:10px;text-align: center;"></td>
                    <td style="text-align:center">{$row['id']}</td>
					<td style="text-align:center">{if $row['pic']}<img src="{php echo tomedia($row['pic']);}" style="width:50px">{/if}</td>
					<td style="text-align:left">{$row['name']}</span></td>
					

<td style="text-align:center">{if $row['isindex']}<label class="label label-success isindex" data-id='{$row["id"]}'>首页</label>{else}<label class="label label-default isindex" data-id='{$row["id"]}'>非首页</label>{/if}</td>	


<td style="text-align:center"><label class="label label-{if $row['bid']!=0}info{else}danger{/if}">
{if $row['bid']!=0}
{if $row['bid']==1}{php $catename="1-服装";}{/if}
{if $row['bid']==2}{php $catename="2-母婴";}{/if}
{if $row['bid']==3}{php $catename="3-化妆品";}{/if}
{if $row['bid']==4}{php $catename="4-居家";}{/if}
{if $row['bid']==5}{php $catename="5-鞋包配饰";}{/if}
{if $row['bid']==6}{php $catename="6-美食";}{/if}
{if $row['bid']==7}{php $catename="7-文体车品";}{/if}
{if $row['bid']==8}{php $catename="8-数码家电";}{/if}
{$catename}
{else}
暂未绑定
{/if}
</label></span></td>


<td style="text-align:center"><label class="label label-{if $row['hid']!=0}info{else}danger{/if}">
{if $row['hid']!=0}
{if $row['hid']==1}{php $catename="1-女装";}{/if}
{if $row['hid']==2}{php $catename="2-男装";}{/if}
{if $row['hid']==3}{php $catename="3-内衣";}{/if}
{if $row['hid']==4}{php $catename="4-美妆";}{/if}
{if $row['hid']==5}{php $catename="5-配饰";}{/if}
{if $row['hid']==6}{php $catename="6-鞋品";}{/if}
{if $row['hid']==7}{php $catename="7-箱包";}{/if}
{if $row['hid']==8}{php $catename="8-儿童";}{/if}
{if $row['hid']==9}{php $catename="9-母婴";}{/if}
{if $row['hid']==10}{php $catename="10-居家";}{/if}
{if $row['hid']==11}{php $catename="11-美食";}{/if}
{if $row['hid']==12}{php $catename="12-数码";}{/if}
{if $row['hid']==13}{php $catename="13-家电";}{/if}
{if $row['hid']==14}{php $catename="14-其他";}{/if}
{$catename}
{else}
暂未绑定
{/if}
</label></span></td>


<td style="text-align:center">{if $row['status']}<label class="label label-success isstatus" data-id='{$row["id"]}'>启用</label>{else}<label class="label label-default isstatus" data-id='{$row["id"]}'>禁用</label>{/if}</td>	


<td style="text-align:center">{if $row['istopstatus']}<label class="label label-success istopstatus" data-id='{$row["id"]}'>启用</label>{else}<label class="label label-default istopstatus" data-id='{$row["id"]}'>禁用</label>{/if}</td>	

<td style="text-align:right">

					

					<a class="btn   btn-default" title="编辑" href="{php echo $this->createWebUrl('listcateall',array('op'=>'post','id'=>$row['id']))}" ><i class="fa fa-edit"></i> 编辑</a>
					
					<a class="btn  btn-danger" rel="tooltip" href="javascript:void();" onclick="drop_confirm('您确定要删除吗?删除不可恢复，同时删除所有相关数据！', '{php echo $this->createWebUrl('listcateall',array('op'=>'del','id'=>$row['id']))}');" title="删除"><i class="fa fa-times"></i></a>
</td>
                </tr>
                {/loop}

				<tr>
	                <td colspan="9" style="text-align: left !important;">
	                	<input name="token" type="hidden" value="{$_W['token']}" />
	                    <!--input type="submit" class="btn btn-primary" name="submit" value="提交排序" /-->

						<a data-href="{php echo $this->createWebUrl('listcateall',array('op'=>'delall'))}" href="javascript:;" class="btn btn-danger mutdelete">删除选中</a>
	                </td>
	            </tr>
            </tbody>
        </table>
        {$pager}
    </div>
</form>
</div>
<script>
function drop_confirm(msg, url){
            if (confirm(msg)){
            window.location = url;
            }
            }

require(['util'],function(util){

$('.mutdelete').click(function(){
            var url = $(this).data('href');
            var ids = [];
            var idss = [];
            $('input:checkbox[name="ids[]"]').each(function() {
                var _that = $(this)[0];
                if(_that.checked){
                    ids = ids.concat($(this).val());
                }else{
                    idss = idss.concat($(this).val());
                }
            });
            console.log(ids);
            if(confirm("您确定要删除么？")){
                $.post(url,{ids:ids},function(data){
                    util.message("删除成功","{php echo $_W['siteurl']}",'success');
                },'json');
            }
        });




$("#checkall").click(function(){
            console.log('checkall');
            $('input[name="ids[]"').each(function(){
                var _that = $(this)[0];
                if(_that.checked){
                    _that.checked = false;
                }else{
                    _that.checked = true;
                }
            });
        });


$("#checkallbottom").click(function(){
            $("#checkall").click();
        });



$('.isstatus').click(function(){
	var label = $(this);
	$.ajax({
		url:'{php echo $this->createWebUrl("listcateall",array("op"=>"status"))}',
		type:'post',
		data:{id:label.attr('data-id')},
		success:function(status){
			if(status == '1'){
				if(label.hasClass('label-success')){
					label.removeClass('label-success').addClass('label-default');
					label.text('禁用');
				}else{
					label.removeClass('label-default').addClass('label-success');
					label.text('启用');
				}
			}
		}
	});
  });



$('.istopstatus').click(function(){
	var label = $(this);
	$.ajax({
		url:'{php echo $this->createWebUrl("listcateall",array("op"=>"istopstatus"))}',
		type:'post',
		data:{id:label.attr('data-id')},
		success:function(status){
			if(status == '1'){
				if(label.hasClass('label-success')){
					label.removeClass('label-success').addClass('label-default');
					label.text('禁用');
				}else{
					label.removeClass('label-default').addClass('label-success');
					label.text('启用');
				}
			}
		}
	});
  });



$('.isindex').click(function(){
	var label = $(this);
	$.ajax({
		url:'{php echo $this->createWebUrl("listcateall",array("op"=>"isindex"))}',
		type:'post',
		data:{id:label.attr('data-id')},
		success:function(status){
			if(status == '1'){
				if(label.hasClass('label-success')){
					label.removeClass('label-success').addClass('label-default');
					label.text('非首页');
				}else{
					label.removeClass('label-default').addClass('label-success');
					label.text('首页');
				}
			}
		}
	});
  });



});
</script>
{elseif $op == 'post'}
<div class='container' style='padding: 0 5px 10px; margin: 0; width: 100%'>
	<ul class="nav nav-tabs">
		<li><a href="{php echo $this->createWebUrl('listcateall');}">分类列表</a></li>

		<li class="active"><a href="{php echo $this->createWebUrl('listcateall',array('op'=>'post'));}">添加/编辑分类</a></li>
	</ul>


<div class="panel panel-info">
		<div class="panel-body">
			<form action="" method="post" class="form-horizontal" role="form">
			<input type="hidden" name="id" value="{$row[id]}">
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">名称</label>
				<div class="col-sm-4">
					<input class="form-control" required="required" name="name" type="text" value="{$row['name']}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">绑定大淘客</label>
					<div class="col-sm-8 col-lg-1">
						<select name="bid" class="form-control">
<option value="0" {if intval($row['bid']) == 0}selected="selected"{/if}>暂未绑定</option>
<option value="1" {if intval($row['bid']) == 1}selected="selected"{/if}>1-服装</option>	
<option value="2" {if intval($row['bid']) == 2}selected="selected"{/if}>2-母婴</option>
<option value="3" {if intval($row['bid']) == 3}selected="selected"{/if}>3-化妆品</option>
<option value="4" {if intval($row['bid']) == 4}selected="selected"{/if}>4-居家</option>
<option value="5" {if intval($row['bid']) == 5}selected="selected"{/if}>5-鞋包配饰</option>
<option value="6" {if intval($row['bid']) == 6}selected="selected"{/if}>6-美食</option>
<option value="7" {if intval($row['bid']) == 7}selected="selected"{/if}>7-文体车品</option>
<option value="8" {if intval($row['bid']) == 8}selected="selected"{/if}>8-数码家电</option>
<option value="9" {if intval($row['bid']) == 9}selected="selected"{/if}>9-男装</option>
<option value="10" {if intval($row['bid']) == 10}selected="selected"{/if}>10-女装</option>
						</select>
					</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">绑定好单库</label>
					<div class="col-sm-8 col-lg-1">
						<select name="hid" class="form-control">
<option value="0" {if intval($row['hid']) == 0}selected="selected"{/if}>暂未绑定</option>
<option value="1" {if intval($row['hid']) == 1}selected="selected"{/if}>1-女装</option>	
<option value="2" {if intval($row['hid']) == 2}selected="selected"{/if}>2-男装</option>
<option value="3" {if intval($row['hid']) == 3}selected="selected"{/if}>3-内衣</option>
<option value="4" {if intval($row['hid']) == 4}selected="selected"{/if}>4-美妆</option>
<option value="5" {if intval($row['hid']) == 5}selected="selected"{/if}>5-配饰</option>
<option value="6" {if intval($row['hid']) == 6}selected="selected"{/if}>6-鞋品</option>
<option value="7" {if intval($row['hid']) == 7}selected="selected"{/if}>7-箱包</option>
<option value="8" {if intval($row['hid']) == 8}selected="selected"{/if}>8-儿童</option>
<option value="9" {if intval($row['hid']) == 9}selected="selected"{/if}>9-母婴</option>
<option value="10" {if intval($row['hid']) == 10}selected="selected"{/if}>10-居家</option>
<option value="11" {if intval($row['hid']) == 11}selected="selected"{/if}>11-美食</option>
<option value="12" {if intval($row['hid']) == 12}selected="selected"{/if}>12-数码</option>
<option value="13" {if intval($row['hid']) == 13}selected="selected"{/if}>13-家电</option>
<option value="14" {if intval($row['hid']) == 14}selected="selected"{/if}>14-其他</option>
						</select>
					</div>
			</div>
			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">排序</label>
				<div class="col-sm-4">
					<input class="form-control" name="displayorder" type="number" min="0" value="{$row['displayorder']}">
				</div>
			</div>

            <div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">首页显示</label>
				<div class="col-sm-4">
					<label><input type="radio" name="isindex" checked="checked" value="0"> 否</label>
					<label style="margin-left: 10px;"><input type="radio" name="isindex" {if $row['isindex']}checked="checked"{/if} value="1"> 是</label>
				</div>
			</div>

			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>
				<div class="col-sm-4">
					<label><input type="radio" name="status" checked="checked" value="0"> 禁用</label>
					<label style="margin-left: 10px;"><input type="radio" name="status" {if $row['status']}checked="checked"{/if} value="1"> 启用</label>
				</div>
			</div>

            <div class="form-group" >
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">图标</label>
                    <div class="col-sm-6 col-xs-12">
                        {php echo tpl_form_field_image('pic', $row['pic']);}
                        <span class="help-block"></span> </div>
            </div>

			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">开启通告</label>
				<div class="col-sm-4">
					<label><input type="radio" name="istopstatus" checked="checked" value="0"> 禁用</label>
					<label style="margin-left: 10px;"><input type="radio" name="istopstatus" {if $row['istopstatus']}checked="checked"{/if} value="1"> 启用</label>
				</div>
			</div>

			<div class="form-group" >
                    <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">通告图</label>
                    <div class="col-sm-6 col-xs-12">
                        {php echo tpl_form_field_image('toppic', $row['toppic']);}
                        <span class="help-block">优先选用通告图片，只需内容请留空此处</span> </div>
            </div>

			<div class="form-group">
				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">通告图URL</label>
				<div class="col-sm-4">
					<input class="form-control" name="topurl" type="text" min="0" value="{$row['topurl']}">
				</div>
			</div>

		  <div class="form-group clearfix">
          <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">通告内容</label>
          <div class="col-sm-6 col-xs-12">
            <!--textarea class="form-control" name="toptxt" placeholder="" rows="6">{$row['toptxt']}</textarea>
            <div class="help-block"></div-->
			{php echo tpl_ueditor('toptxt', $row['toptxt']);}
          </div>
           </div>

			<button type="submit" class="btn btn-primary" name="submit" value="提交">保存</button>
			<input type="hidden" name="token" value="{$_W['token']}" />
			</form>
	</div>
</div>

</div>
{/if}
{template 'footer'}